<template>
  <div class="rank">
    <div class="tab">
      <div class="tab-tit clearfix">
        <a v-for="(tab, index) in tabs" :key="index" :class="{ on: currentTab === index }" @click="selectTab(index)">
          <p class="img">
            <i></i>
          </p>
          <p class="text">{{ tab.title }}</p>
        </a>
      </div>
    </div>
    <div class="content">
      <ul>
        <li v-for="item in tabs[currentTab].items" :key="item.id">
          <div class="img-item">
            <p class="tab-pic">
              <a href="#">
                <img :src="item.image" alt="商品图片" />
              </a>
            </p>
            <div class="tab-info">
              <div class="info-title">
                <a href="#">{{ item.title }}</a>
              </div>
              <p class="info-price">定金：{{ item.price }}</p>
            </div>
          </div>

          <div class="img-item">
            <p class="tab-pic">
              <a href="#">
                <img :src="item.image" alt="商品图片" />
              </a>
            </p>
            <div class="tab-info">
              <div class="info-title">
                <a href="#">{{ item.title }}</a>
              </div>
              <p class="info-price">定金：{{ item.price }}</p>
            </div>
          </div>

          <div class="img-item">
            <p class="tab-pic">
              <a href="#">
                <img :src="item.image" alt="商品图片" />
              </a>
            </p>
            <div class="tab-info">
              <div class="info-title">
                <a href="#">{{ item.title }}</a>
              </div>
              <p class="info-price">定金：{{ item.price }}</p>
            </div>
          </div>

          <div class="img-item">
            <p class="tab-pic">
              <a href="#">
                <img :src="item.image" alt="商品图片" />
              </a>
            </p>
            <div class="tab-info">
              <div class="info-title">
                <a href="#">{{ item.title }}</a>
              </div>
              <p class="info-price">定金：{{ item.price }}</p>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <div class="line"></div>
</template>

<script>
export default {
  data() {
    return {
      currentTab: 0,
      tabs: [
        {
          title: '热卖排行',
          items: [
            { id: 1, image: require('./images/1.jpg'), title: '【官网价直降1100】Apple iPhone 14Plus 256GB 银色 移动联通电信4G手机', price: '¥5999.00' }
          ]
        },
        {
          title: '特价排行',
          items: [
            { id: 2, image: require('./images/1.jpg'), title: '特价商品,优惠多多,限时抢购！', price: '¥3999.00' }
          ]
        },
        {
          title: '新品排行',
          items: [
            { id: 3, image:require('./images/1.jpg'), title: '新品推荐,热卖中,欢迎体验！', price: '¥4099.00' }
          ]
        }
      ]
    };
  },
  methods: {
    selectTab(index) {
      if (index >= 0 && index < this.tabs.length) {
        this.currentTab = index;
      } else {
        console.error("Tab index is out of bounds");
      }
    },
  }
};
</script>

<style scoped>
.line {
  width: 1200px;
  height: 1px;
  background: #e8e3e2;
  margin: 20px auto;
}
.rank {
  width: 1200px;
  margin: 0 auto;
}
.tab {
  overflow: hidden;
  width: 312px;
  margin: 0 auto;
}
.tab-tit {
  text-align: center;
}
.tab-tit a {
  display: block;
  padding: 0 18px;
  float: left;
  text-decoration: none;
  font-size: 16px;
  color: #999;
  cursor: pointer;
}
.tab-tit a p {
  margin: 5px 0;
}
.tab-tit a .img i {
  width: 35px;
  height: 35px;
  display: block;
  background: url(./images/bg0.png) no-repeat;
  margin-left: 10px;
}
.tab-tit a .text {
  line-height: 28px;
}
.tab-tit .on {
  color: #e60012;
}
.tab-tit .on .img i {
  background-position: -35px 0;
}
.content {
  display: flex;
  justify-content: space-around;
  /* overflow: hidden; */
  /* margin: 0px auto; */
  /* padding: 10px; */
}
.content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.content ul li {
  overflow: hidden;
  line-height: 18px;
  margin-bottom: 10px;
}
.img-item {
  border: 1px solid #e1251b;
  width: 270px;
  float: left;
  overflow: hidden;
  margin: 10px 12px;
  background: #fff;
}
.tab-pic {
  width: 230px;
  height: 210px;
  overflow: hidden;
  text-align: center;
  margin: 5px auto 18px;
}
.tab-pic a img {
  width: 200px;
  height: 200px;
}
.tab-info {
  background: #fafafa;
}
.info-title {
  height: 50px;
  line-height: 28px;
  overflow: hidden;
  margin: 0 auto;
  padding-left: 10px;
}
.info-title a {
  color: #333;
  text-decoration: none;
}
.info-price {
  font-size: 20px;
  color: #e1251b;
  height: 35px;
  padding-left: 10px;
  display: block;
  line-height: 24px;
  margin: 10px auto 0;
}
</style>